package com.hh.admin.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.hh.admin.entity.SysLoginLog;
import com.hh.admin.service.ISysLoginLogService;
import com.hh.admin.view.LogView;
import com.hh.core.annotion.OperationLog;
import com.hh.core.common.BaseController;
import com.hh.core.entity.ResultEntity;
import com.hh.core.enums.OperationLogEnum;

@Controller
@RequestMapping("/admin/sysLoginLog")
public class SysLoginLogController extends BaseController{

	@Autowired
	ISysLoginLogService sysLoginLogService;
	
	/**
	 * 
	* @Title: index  
	* @Description:   登录日志页面
	* @param @return    设定文件  
	* @return String    返回类型  
	* @author hxn
	* @date 2018年2月13日 上午10:57:06  
	* @throws
	 */
	@RequestMapping(value = "", method = RequestMethod.GET)
	public String index(){
		return LogView.LOGINLOG_INDEX;
	}
	
	/**
	 * 
	* @Title: loginLogList  
	* @Description:   登录日志分页
	* @param @param pageSize
	* @param @param pageNumber
	* @param @param loginLog
	* @param @return    设定文件  
	* @return JSONObject    返回类型  
	* @author hxn
	* @date 2018年2月13日 上午11:03:22  
	* @throws
	 */
	@ResponseBody
	@RequestMapping(value = "/list", method = RequestMethod.POST)
	public JSONObject loginLogList(int pageSize, int pageNumber,SysLoginLog loginLog){
		Page<SysLoginLog> page = new Page<SysLoginLog>(pageNumber,pageSize,"id");
		page.setAsc(false);
		EntityWrapper<SysLoginLog> entityWrapper = new EntityWrapper<>();
		entityWrapper.setEntity(loginLog);
		page = sysLoginLogService.selectPage(page, entityWrapper);
		return pageJosn(page);
	}
	
	/**
	 * 
	* @Title: delete  
	* @Description:   删除登录日志
	* @param @return    设定文件  
	* @return ResultEntity    返回类型  
	* @author hxn
	* @date 2018年2月13日 上午11:03:15  
	* @throws
	 */
	@RequestMapping(value = "/delete", method = RequestMethod.POST)
	@ResponseBody
	@OperationLog(value="清空登录日志",type=OperationLogEnum.DELETE)
	public ResultEntity delete(){
		int count = sysLoginLogService.deleteAMonthAgo();
		return successResult("删除成功!共删除"+count+"条");
	}
}
